package edu.ncu.controller;

import edu.ncu.entity.News;
import edu.ncu.service.NewsService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
@RequestMapping("/news")
public class NewsController {
    final NewsService newsService;

    public NewsController(NewsService newsService) {
        this.newsService = newsService;
    }

    //查看所有新闻
    @RequestMapping("/findAll")
    public String findAll(Model model)
    {
        System.out.println("表现层:findAll方法执行了...");
        //调用service方法,需要service层的对象,需要注入
        List<News> news = newsService.findAll();
        System.out.println(news);
        model.addAttribute("news", news);
        return "/newsSquare";
    }
}
